<?php

namespace App\Observers;

use App\Models\Clue;
use App\User;

class ClueObserver
{
    public function created(Clue $clue)
    {
        $type = $clue->type;

        $online = getOnlineUser("user:$type");

        if ($online && $id = array_first($online)) {
            $online = array_diff($online, [$id]);
            $clue->distributions()->attach($id);
            array_push($online, $id);

            setOnlineUser("user:$type", $online);
        }
    }
}
